Public Class frmLogin
    Dim cData As VirtualDesk.Data
    Dim doCrypt As VirtualDesk.Encrypt
    Private Sub DoLogin()
        If Me.txtUserName.Text.Trim = "" Then
            MessageBox.Show("Invalid UserName", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        If Me.txtPassword.Text.Trim = "" Then
            MessageBox.Show("Invalid Password", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            Exit Sub
        End If
        cData = New VirtualDesk.Data
        Dim I As Integer
        Dim CHKPASS As String
        Dim chkStatus As Boolean = False
        cData.DS_Read("SELECT * FROM TBL_ACCOUNT WHERE ACCT_USERNAME='" & Me.txtUserName.Text.Trim & "'", "DSUSER")
        If cData.DSdata.Tables(0).Rows.Count > 0 Then
            For I = 0 To cData.DSdata.Tables(0).Rows.Count - 1
                doCrypt = New Encrypt
                CHKPASS = doCrypt.decryption(cData.DSdata.Tables(0).Rows(I).Item("ACCT_PASSWORD"))
                If CHKPASS = Me.txtPassword.Text.Trim Then
                    chkStatus = True
                    FrmMain.UserAccoutnID = cData.DSdata.Tables(0).Rows(I).Item(0)
                    FrmMain.UserFullName = cData.DSdata.Tables(0).Rows(I).Item("ACCT_NAME") & " " & cData.DSdata.Tables(0).Rows(I).Item("ACCT_LASTNAME")
                    Exit For
                End If
            Next
            If chkStatus = True Then
                Me.DialogResult = Windows.Forms.DialogResult.Yes
            Else
                MessageBox.Show("Invalid Login Information", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End If
        Else
            MessageBox.Show("Invalid Login Information", "Virutal Desk", MessageBoxButtons.OK, MessageBoxIcon.Warning)

        End If
    End Sub

  

    Private Sub btn_cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_cancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.No
        Application.ExitThread()

    End Sub

    Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click
        DoLogin()

    End Sub

    Private Sub txtPassword_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtPassword.KeyPress
        If e.KeyChar = Chr(13) Then
            DoLogin()
        End If
    End Sub

    Private Sub txtUserName_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtUserName.KeyPress
        If e.KeyChar = Chr(13) Then
            DoLogin()
        End If
    End Sub

  
End Class